define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'workflow/index' + location.search,
                    add_url: 'workflow/add',
                    //edit_url: 'workflow/edit',
                    del_url: 'workflow/del',
                    multi_url: 'workflow/multi',
                    import_url: 'workflow/import',
                    table: 'workflow',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'warranty_id', title: __('Warranty_id')},
                        {field: 'warranty.workID', title: __('Warranty.workID')},
                        /*{field: 'hospital_id', title: __('Hospital_id')},
                        {field: 'user_id', title: __('User_id')},*/
                        {field: 'type_data', title: __('Type_data'), searchList: {"0":__('Type_data 0'),"1":__('Type_data 1'),"2":__('Type_data 2'),"3":__('Type_data 3'),"4":__('Type_data 4'),"5":__('Type_data 5'),"6":__('Type_data 6'),"7":__('Type_data 7'),"8":__('Type_data 8')}, formatter: Table.api.formatter.normal},
                        //{field: 'type_id', title: __('Type_id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'number', title: __('Number')},
                        {field: 'types_data', title: __('Types_data'), searchList: {"0":__('Types_data 0'),"1":__('Types_data 1')}, formatter: Table.api.formatter.normal},
                        {field: 'a.name', title: __('Warranty.product'), operate: 'LIKE'},
                        {field: 'a.marking', title: __('Warranty.device'), operate: 'LIKE'},
                        {field: 'hospital.name', title: __('Hospital.name'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE', formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons: [
                                {
                                    name: 'see',
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    text: __('详情'),   icon: '',
                                    url: 'workflow/see'
                                },
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            table.bootstrapTable('hideColumn','warranty_id');
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
